package com.hujing;

import java.time.Duration;
import java.time.LocalDateTime;

/**
 * Duration的作用：
 * 可以用于计算两个对象之间相差的天数，小时数，分钟数，秒数，纳秒数。
 * 支持LocalTime,LocalDateTime,Instant
 */
public class DurationDemo {

    public static void main(String[] args) {
        LocalDateTime start = LocalDateTime.of(2025, 3, 10, 11, 11, 11);
        LocalDateTime end = LocalDateTime.of(2025, 3, 10, 12, 12, 12);
        Duration duration = Duration.between(start, end);

        //相差的天数
        System.out.println(duration.toDays());
        //相差的小时数
        System.out.println(duration.toHours());
        //相差的分钟数
        System.out.println(duration.toMinutes());
        //相差的秒数
        System.out.println(duration.getSeconds());
        //相差的纳秒数
        System.out.println(duration.toNanos());
    }
}
